package star.servlet_2;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * 重定向和转发的区别
 * 相同点：页面都会实现跳转
 * 不同点：请求转发的时候，url不会发生变化； 重定位时会发生变化
 */
public class redirect_8 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //重定向
        /**         等价于这两步
         *         resp.setHeader("Location","/Servlet_2_war/image");
         *         resp.setStatus(302);
         */
        resp.sendRedirect("/Servlet_2_war/image");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
